<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="../Ajs/vue.js"></script>
    <script src="../Ajs/vue-router.js"></script>
</head>
<body>
<div id="box">


    <router-link to="/user/1">user1</router-link>
    <router-link to="/user/2">user2</router-link>
    <router-link :to="{name:'user',params:{id:3}}">user3</router-link>
    <router-view></router-view>

</div>

    <script>

        const User = {
            props:["uname","age","id"],
            template:"<div>{{id}} -- {{uname}} -- {{age}}</div>"
        };

        var router = new VueRouter({


            routes:[
                {path:"/",redirect:"/user"},

                //如果 props 是一个函数，则这个函数接收 route 对象为自己的形参，
                //向组件props 传值
                {
                    name: "user",
                    path:"/user/:id",
                    component:User,
                    props:function(route){
                        return {
                            uname:"jankin",
                            age:22,
                            id:route.params.id
                        }
                    }
                }
            ]
        });

        var vm = new Vue({
            el:"#box",
            //挂载路由实例对象
            router:router,
            data:{

            }
        })
    </script>
</body>
</html>